import Vue from 'vue'
import VueRouter from 'vue-router'
import Register from '../views/Register.vue'
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'
import routerList from "../utils/routerList";
import question from "../views/pages/Questionjump/add.vue"

import particulars from "../views/pages/collection/jump/particulars.vue"
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: Login
  },
  // {
  //   path: '/',
  //   name: 'login',
  //   default: login
  // },

  {
    path: '/register',
    name: 'register',
    component: Register
  },
  {
    path: '/home',
    name: 'home',
    components: {
      default: Home
    },
    children: routerList
  },
  {
    path: '/questionjump',
    name: 'questionjump',
    component: question
  },
 {
    path: '/particulars',
    name: "particulars",
    component: particulars
  }
]

// 防止重复点击路由报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// 路由守卫
// router.beforeEach((to, from, next) => {
//   let token = sessionStorage.getItem('token');
//   if (token) {
//     next()
//   } else {
//     if (to.path === '/login') {
//       next()
//     } else {
//       next(`/login?redirect=${to.path}`)

//     }
//   }
// })
export default router
